package com.rabbitmq.provider.controller;

import com.rabbitmq.provider.config.redis.RedisUtil;
import com.rabbitmq.provider.entity.UserEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author wangdong
 * @data 2020/03/03 0003 15:38
 * @DAY 星期二
 * @描述
 */
@Api(value = "redis接口", tags = {"redis接口"})
@Scope("prototype")
@RestController
public class RedisController {

    /**
     * redis中存储的过期时间60s
     */
    private static int ExpireTime = 60;

    @Autowired
    private RedisUtil redisUtil;

    @ApiOperation(value = "普通缓存放入", notes = "普通缓存放入接口")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/set", method = RequestMethod.POST)
    public boolean redisSet(String key, String value){
        UserEntity userEntity =new UserEntity();
        userEntity.setId("1");
        userEntity.setGuid(String.valueOf(1));
        userEntity.setName("dong");
        userEntity.setAge(String.valueOf(20));
        userEntity.setCreateTime("");

        return redisUtil.set(key,userEntity,ExpireTime);

        //return redisUtil.set(key,value);
    }

    @ApiOperation(value = "普通缓存获取", notes = "普通缓存获取接口")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public Object redisGet(String key){
        return redisUtil.get(key);
    }

    @ApiOperation(value = "指定缓存失效时间", notes = "指定缓存失效时间接口")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/expire", method = RequestMethod.POST)
    public boolean expire(String key){
        return redisUtil.expire(key,ExpireTime);
    }
}
